package com.realtyManage.springboot.Service.impl;

import com.microsoft.schemas.office.visio.x2012.main.CellType;
import com.realtyManage.springboot.Dao.CustomerRegistrationRepository;
import com.realtyManage.springboot.Dao.HouseDetailRepository;
import com.realtyManage.springboot.Dao.UserRepository;
import com.realtyManage.springboot.Model.Do.CustomerRegistration;
import com.realtyManage.springboot.Model.Do.HouseDetail;
import com.realtyManage.springboot.Model.Vo.HouseDetailEntity;
import com.realtyManage.springboot.Model.Vo.HouseEntity;
import com.realtyManage.springboot.Model.Vo.UserTaskEntity;
import com.realtyManage.springboot.Service.IHouseDetailService;
import com.realtyManage.springboot.Service.ISpecialOfferHouseService;
import com.realtyManage.springboot.Service.IUserService;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.persistence.criteria.Predicate;
import javax.servlet.http.HttpServletRequest;
import javax.transaction.Transactional;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;

import static org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC;
import static org.apache.poi.ss.usermodel.Cell.CELL_TYPE_STRING;

/**
 * HouseDetailService
 *
 * @Author 杭州素色网络科技有限公司
 * @Date 2019/3/29
 **/
@Service
@Transactional
public class HouseDetailServiceImpl implements IHouseDetailService {
    @Autowired
    private HouseDetailRepository houseDetailRepository;
    @Autowired
    private ISpecialOfferHouseService specialOfferHouseService;
    @Autowired
    private UserRepository userRepository;
    @Autowired
    private CustomerRegistrationRepository customerRegistrationRepository;
    @Autowired
    private IUserService userService;


    @Override
    public List<HouseDetail> findAll() {
        return houseDetailRepository.findAll();
    }

    /*
    * @Author Danny
    * @Description //TODO 
    * @Date 2019/3/29
    * @Param [houseEntity]
    * @Return java.util.List<HouseDetail>
    **/
    @Override
    public Page<HouseDetail> findPagedByWhereClause(HouseEntity houseEntity) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Integer pageNumber = houseEntity.getPageNumber()-1;
        Integer pageSize = houseEntity.getPageSize();
        //系统时间
        String thisTime = (sdf.format(new Date())).toString();
        //排序条件
        //默认最新
        Sort sort = new Sort(Sort.Direction.ASC, "id");
        /*if (houseEntity.getReorder() != null && houseEntity.getReorder() != ""){
            if (houseEntity.getReorder().equals("均价升序")){
                //均价升序
                sort = new Sort(Sort.Direction.ASC, "referPrice");
            }else if (houseEntity.getReorder().equals("均价降序")){
                //均价降序
                sort = new Sort(Sort.Direction.DESC, "referPrice");
            }
        }*/
        Pageable pageable = PageRequest.of(pageNumber,pageSize,sort);
        //动态查询条件
        Specification<HouseDetail> specification = (Specification<HouseDetail>)(root, query, criteriaBuilder) -> {
            List<Predicate> list = new ArrayList<>();
            System.out.println("参数============================》"+houseEntity.getBlockCode());
            Predicate p0 = criteriaBuilder.equal(root.get("isShow"),0);
            list.add(p0);
            if (houseEntity.getBlockCode()!=null) {
                //根据幢号查询
                Predicate p1 = criteriaBuilder.equal(root.get("blockCode"),houseEntity.getBlockCode());
                list.add(p1);
            }
            if (houseEntity.getUnitCode()!=null) {
                // 单元号查询
                Predicate p2 = criteriaBuilder.equal(root.get("unitCode"),houseEntity.getUnitCode());
                list.add(p2);
            }
            if (houseEntity.getDoorplateCode()!=null) {
                // 门牌号
                Predicate p3 = criteriaBuilder.equal(root.get("doorplateCode"),houseEntity.getDoorplateCode());
                list.add(p3);
            }
            if (houseEntity.getHouseType()!=null) {
                    // 物业类型
                    Predicate p4 = criteriaBuilder.like(root.get("propertyTye"),houseEntity.getHouseType());   
                    list.add(p4);
            }
            if (houseEntity.getFloor()!=null) {
                //楼层查询
                    Predicate p5 = criteriaBuilder.equal(root.get("floor"),houseEntity.getFloor());
                    list.add(p5);
            }
            if (houseEntity.getApartmentNumber()!=null){
                //户型编号
                Predicate p6 =criteriaBuilder.equal(root.get("apartmentNumber"),houseEntity.getApartmentNumber());
                list.add(p6);
            }
            if (houseEntity.getArchitectureArea()!=null && houseEntity.getArchitectureAreaE() != null){
                //建筑面积
                Predicate p7 =criteriaBuilder.between(root.get("architectureArea"),Integer.valueOf(houseEntity.getArchitectureArea()),Integer.valueOf(houseEntity.getArchitectureAreaE()));
                list.add(p7);
            }else if (houseEntity.getArchitectureArea()!=null && houseEntity.getArchitectureAreaE() == null){
                Predicate p7 =criteriaBuilder.equal(root.get("architectureArea"),houseEntity.getArchitectureArea());
                list.add(p7);
            }else if (houseEntity.getArchitectureArea()==null && houseEntity.getArchitectureAreaE() != null){
                Predicate p7 =criteriaBuilder.equal(root.get("architectureArea"),houseEntity.getArchitectureAreaE());
                list.add(p7);
            }
            if (houseEntity.getApartmentStructure()!=null){
                //户型结构
                Predicate p8 =criteriaBuilder.equal(root.get("apartmentStructure"),houseEntity.getApartmentStructure());
                list.add(p8);
            }
            if (houseEntity.getJacketed()!=null){
                //套型
                Predicate p9 =criteriaBuilder.equal(root.get("jacketed"),houseEntity.getJacketed());
                list.add(p9);
            }
            if (houseEntity.getDiscountPrice()!=null){
                //优惠单价
                Predicate p10 =criteriaBuilder.equal(root.get("discountPrice"),houseEntity.getDiscountPrice());
                list.add(p10);
            }
            if (houseEntity.getDiscountTotal()!=null && houseEntity.getDiscountTotalE() != null){
                //优惠总价
                Predicate p11 =criteriaBuilder.between(root.get("discountTotal"),Integer.valueOf(houseEntity.getDiscountTotal()),Integer.valueOf(houseEntity.getDiscountTotalE()));
                list.add(p11);
            }else if (houseEntity.getDiscountTotal()!=null && houseEntity.getDiscountTotalE() == null){
                Predicate p11 =criteriaBuilder.equal(root.get("discountTotal"),houseEntity.getDiscountTotal());
                list.add(p11);
            }else if (houseEntity.getDiscountTotal()==null && houseEntity.getDiscountTotalE() != null){
                Predicate p11 =criteriaBuilder.equal(root.get("discountTotal"),houseEntity.getDiscountTotalE());
                list.add(p11);
            }
            if (houseEntity.getStage()!=null){
                //期数
                Predicate p12 =criteriaBuilder.equal(root.get("stage"),houseEntity.getStage());
                list.add(p12);
            }
            if (houseEntity.getFace()!=null){
                //期数
                Predicate p13 =criteriaBuilder.equal(root.get("face"),houseEntity.getFace());
                list.add(p13);
            }
            if(houseEntity.getType() != null){
                if(houseEntity.getType().equals("0")){
                    //是否查询在售房源   type = 0
                    Predicate p14 = criteriaBuilder.equal(root.get("type"),houseEntity.getType());
                    list.add(p14);
                }
            }
            //在售
           /* Predicate p14 =criteriaBuilder.equal(root.get("type"),0);
            list.add(p14);*/
            return criteriaBuilder.and(list.toArray(new Predicate[0]));
        };
        Page<HouseDetail> lst = houseDetailRepository.findAll(specification, pageable);

        //统计特价房数量
        /*for(HouseDetail houseDetail : lst.getContent()){
            houseDetail.setCustNum(specialOfferHouseService.countByRelevanceHouseId(houseDetail.getId()));
            //判断合作日期是否已过   sdf.format(new Date())
            if (houseDetail.getMaturityTime() != null){
            int result = houseDetail.getMaturityTime().compareTo(thisTime);
            if (result > 0){
                houseDetail.setMaturityType(1);
            }else{
                houseDetail.setMaturityType(0);
            }
            }else{
                houseDetail.setMaturityType(0);
            }
        }*/
        return lst;
    }


    @Override
    public int saveHouseInfo(HouseDetail houseDetail) {
        houseDetailRepository.saveAndFlush(houseDetail);
            return 1;
    }

    @Override
    public boolean updateHouseInfo(HouseDetail houseDetail) {
        if(houseDetailRepository.update(houseDetail)==1){
            return true;
        }else{
            return false;
        }
    }

    public boolean updateHouseType(HouseDetail houseDetail) {
        if(houseDetailRepository.updateHouseType(houseDetail) >= 1){
            return true;
        }else{
            return false;
        }
    }

    public boolean updateHouseTypeN(Integer id,Integer artificial) {
        if(houseDetailRepository.updateHouseTypeN(id,artificial) >= 1){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public List<String> findByNameLike(String houseName) {
        return houseDetailRepository.findByNameLike(houseName);
    }


    @Override
    public  String getName(Integer id){
        return  houseDetailRepository.getName(id);
    }

    @Override
    public String getId(String userId){
        return houseDetailRepository.getId(userId);
    }

    @Override
    public int deleteHouse(String ids){
        String idArr[] = ids.split(",");
        List id = new ArrayList();
        for (String ar : idArr){
            id.add(ar);
        }
        return  houseDetailRepository.deleteHouse(id);
    }

    @Override
    public List<HouseDetail> querySpecial() {
        return houseDetailRepository.querySpecial();
    }

    @Override
    public List<String> getHouseParameter(String type) {
        List<String> lst = null;
        //根据type获取参数列表
        if(type.equals("jzmj")){
            //建筑面积
            lst = houseDetailRepository.getArchitectureArea();
        }else if (type.equals("wylx")){
            //物业类型
            lst = houseDetailRepository.getPropertyTye();
        }else if(type.equals("zh")){
            //幢号
            lst = houseDetailRepository.getBlockCode();
        }else if (type.equals("lc")){
            //楼层
            lst = houseDetailRepository.getFloor();
        }else if (type.equals("hxbh")){
            //户型编号
            lst = houseDetailRepository.getApartmentNumber();
        }else if (type.equals("hxjg")){
            //户型结构
            lst = houseDetailRepository.getApartmentStructure();
        }else if (type.equals("tx")){
            //套型
            lst = houseDetailRepository.getJacketed();
        }else if (type.equals("yhdj")){
            //优惠单价
            lst = houseDetailRepository.getDiscountPrice();
        }else if (type.equals("yhzj")){
            //优惠总价
            lst = houseDetailRepository.getDiscountTotal();
        }
        return lst;
    }


    @Override
    public List<HouseDetail> houseMarketingControl(UserTaskEntity userTaskEntity) {
        //动态查询条件
        Specification<HouseDetail> specification = (Specification<HouseDetail>)(root, query, criteriaBuilder) -> {
            List<Predicate> list = new ArrayList<>();
            if (userTaskEntity.getBlockCode()!=null) {
                // 根据幢号查询
                Predicate p1 = criteriaBuilder.equal(root.get("blockCode"),userTaskEntity.getBlockCode());
                list.add(p1);
            }
            if (userTaskEntity.getPropertyTye()!=null) {
                // 根据物业类型查询
                Predicate p2 = criteriaBuilder.equal(root.get("propertyTye"),userTaskEntity.getPropertyTye() );
                list.add(p2);
            }
            if (userTaskEntity.getStage()!=null) {
                // 根据物业类型查询
                Predicate p3 = criteriaBuilder.equal(root.get("stage"),userTaskEntity.getStage() );
                list.add(p3);
            }

            return criteriaBuilder.and(list.toArray(new Predicate[0]));
        };
        List<HouseDetail> lst = houseDetailRepository.findAll(specification);
        return lst;

    }


    @Override
    public HashMap<String,Integer> houseMarketingControl1(UserTaskEntity userTaskEntity) {
        HashMap<String,Integer> map = new HashMap<String,Integer>();
        //动态查询条件
        Specification<HouseDetail> specification = (Specification<HouseDetail>)(root, query, criteriaBuilder) -> {
            List<Predicate> list = new ArrayList<>();
            if (userTaskEntity.getBlockCode()!=null) {
                // 根据幢号查询
                Predicate p1 = criteriaBuilder.equal(root.get("blockCode"),userTaskEntity.getBlockCode());
                list.add(p1);
            }
            if (userTaskEntity.getPropertyTye()!=null) {
                // 根据物业类型查询
                Predicate p2 = criteriaBuilder.equal(root.get("propertyTye"),userTaskEntity.getPropertyTye() );
                list.add(p2);
            }
            if (userTaskEntity.getStage()!=null) {
                // 根据物业类型查询
                Predicate p3 = criteriaBuilder.equal(root.get("stage"),userTaskEntity.getStage() );
                list.add(p3);
            }
            return criteriaBuilder.and(list.toArray(new Predicate[0]));
        };
        List<HouseDetail>  lst = houseDetailRepository.findAll(specification);
        //定义在售，已定，已售变量
        Integer salable = 0,fixed = 0,sold = 0;
        //循环遍历其中房源状态及销控状态
        for(HouseDetail houseDetail : lst){
            System.out.println("=====102========>"+houseDetail.getDoorplateCode());
            if (houseDetail.getArtificial() == 0){
                if (houseDetail.getType().equals("0") || houseDetail.getType().equals("1") || houseDetail.getType().equals("2")){
                    salable ++;
                }else if (houseDetail.getType().equals("3")){
                    fixed ++;
                }else if (houseDetail.getType().equals("4")){
                    sold ++;
                }
            }else{
                if (houseDetail.getArtificial() == 0 || houseDetail.getArtificial() == 2){
                    salable ++;
                }else if (houseDetail.getArtificial() == 1){
                    fixed ++;
                }else if (houseDetail.getArtificial() == 3){
                    sold ++;
                }
            }
        }
        map.put("salable",salable);
        map.put("fixed",fixed);
        map.put("sold",sold);
        return map;
    }

    @Override
    public List<String> getPropertyTye() {
        return houseDetailRepository.getPropertyTye();
    }

    @Override
    public List<String> getStage() {
        return houseDetailRepository.getStage();
    }

    @Override
    public List<String> getBlockCode() {
        return houseDetailRepository.getBlockCode();
    }

    @Override
    public int importPriceList(MultipartFile file, HttpServletRequest request){
        List<HouseDetail> list = new ArrayList<HouseDetail>();
        //1.得到上传的表
        Workbook workbook2 = null;
        try {
            workbook2 = WorkbookFactory.create(file.getInputStream());
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InvalidFormatException e) {
            e.printStackTrace();
        }
        //2、获取sheet1工作表
        Sheet sheet2 = workbook2.getSheet("备案价明细");
        //获取表的总行数
        int num = sheet2.getLastRowNum();
        //总列数
        int col = sheet2.getRow(0).getLastCellNum();
        //遍历excel每一行
        for (int j = 1; j < num + 1; j++) {
            Row row1 = sheet2.getRow(j);
            //获取表中第i行，第1列的单元格
            Cell cell3 = row1.getCell(0);  //期数
            if (cell3 != null){
                cell3.setCellType(CELL_TYPE_STRING);
            }
            Cell cell4 = row1.getCell(1);  //撞号
            if(cell4 != null){
                cell4.setCellType(CELL_TYPE_STRING);
            }
            Cell cell5 = row1.getCell(2);  //单元号
            if (cell5 != null){
                cell5.setCellType(CELL_TYPE_STRING);
            }
            Cell cell6 = row1.getCell(3);  //楼层
            if (cell6 != null){
                cell6.setCellType(CELL_TYPE_STRING);
            }
            Cell cell7 = row1.getCell(4);  //房号
            if (cell7 != null){
                cell7.setCellType(CELL_TYPE_STRING);
            }
            Cell cell8 = row1.getCell(5);  //户型编号
            if (cell8 != null){
                cell8.setCellType(CELL_TYPE_STRING);
            }
            Cell cell9 = row1.getCell(6);  //建筑面积
            if(cell9 != null){
                cell9.setCellType(CELL_TYPE_STRING);
            }
            Cell cell10 = row1.getCell(7);  //套内面积
            if (cell10 != null){
                cell10.setCellType(CELL_TYPE_STRING);
            }
            Cell cell11 = row1.getCell(8);  //公摊面积
            if (cell11 != null){
                cell11.setCellType(CELL_TYPE_STRING);
            }
            Cell cell12 = row1.getCell(9);  //得房率
            if (cell12 != null){
                cell12.setCellType(CELL_TYPE_STRING);
            }
            Cell cell13 = row1.getCell(10);  //赠送面积
            if (cell13 != null){
                cell13.setCellType(CELL_TYPE_STRING);
            }
            Cell cell14 = row1.getCell(11);  //实际使用面积
            if (cell14 != null){
                cell14.setCellType(CELL_TYPE_STRING);
            }
            Cell cell15 = row1.getCell(12);  //物业类型
            if (cell15 != null){
                cell15.setCellType(CELL_TYPE_STRING);
            }
            Cell cell16 = row1.getCell(13);  //户型结构
            if (cell16 != null){
                cell16.setCellType(CELL_TYPE_STRING);
            }
            Cell cell17 = row1.getCell(14);  //朝向
            if (cell17 != null){
                cell17.setCellType(CELL_TYPE_STRING);
            }
            Cell cell18 = row1.getCell(15);  //庭院面积
            if (cell18 != null){
                cell18.setCellType(CELL_TYPE_STRING);
            }
            Cell cell19 = row1.getCell(16);  //备案单价
            if (cell19 != null){
                cell19.setCellType(CELL_TYPE_STRING);
            }
            Cell cell20 = row1.getCell(17);  //备案总价
            if (cell20 != null){
                cell20.setCellType(CELL_TYPE_STRING);
            }
            Cell cell21 = row1.getCell(18);  //现售单价
            if (cell21 != null){
                cell21.setCellType(CELL_TYPE_STRING);
            }
            Cell cell22 = row1.getCell(19);  //现售总价
            if (cell22 != null){
                cell22.setCellType(CELL_TYPE_STRING);
            }
            Cell cell23 = row1.getCell(20);  //优惠单价
            if (cell23 != null){
                cell23.setCellType(CELL_TYPE_STRING);
            }
            Cell cell24 = row1.getCell(21);  //优惠总价
            if (cell24 != null){
                cell24.setCellType(CELL_TYPE_STRING);
            }
            Cell cell25 = row1.getCell(22);  //关注度
            if (cell25 != null){
                cell25.setCellType(CELL_TYPE_STRING);
            }
            Cell cell26 = row1.getCell(23);  //房源状态     ----1.2.3
            if (cell26 != null){
                cell26.setCellType(CELL_TYPE_STRING);
            }
            Cell cell27 = row1.getCell(24);  //销售员
            if (cell27 != null){
                cell27.setCellType(CELL_TYPE_STRING);
            }
            Cell cell28 = row1.getCell(25);  //业主名
            if (cell28 != null){
                cell28.setCellType(CELL_TYPE_STRING);
            }
            Cell cell29 = row1.getCell(26);  //备注
            if (cell29 != null){
                cell29.setCellType(CELL_TYPE_STRING);
            }
            Cell cell30 = row1.getCell(27);  //领导建议
            if (cell30 != null){
                cell30.setCellType(CELL_TYPE_STRING);
            }
           // Cell cell31 = row1.getCell(28);  //操作

            //这里new 一个对象，用来装填从页面上传的Excel数据，字段根据上传的excel决定
            HouseDetail excel= new HouseDetail();
            if (cell3 != null){
                excel.setStage(cell3.toString());
            }
            if (cell4 != null){
                excel.setBlockCode(Integer.valueOf(cell4.toString()));
            }
            if (cell5 != null){
                excel.setUnitCode(cell5.toString());
            }
            if (cell6 != null){
                excel.setFloor(cell6.toString());
            }
            if (cell7 != null){
                excel.setDoorplateCode(cell7.toString());
            }
            if (cell8 != null){
                excel.setApartmentNumber(cell8.toString());
            }
            if (cell9 != null){
                excel.setArchitectureArea(cell9.toString());
            }
            if (cell10 != null){
                excel.setIndoorArea(cell10.toString());
            }
            if (cell11 != null){
                excel.setPublicArea(cell11.toString());
            }
            if (cell12 != null){
                excel.setRoomRate(cell12.toString());
            }
            if (cell13 != null){
                excel.setApartmentStructure(cell13.toString());
            }
            if (cell14 != null){
                excel.setActualUseArea(cell14.toString());
            }
            if (cell15 != null){
                excel.setPropertyTye(cell15.toString());
            }
            if (cell16 != null){
                excel.setApartmentStructure(cell16.toString());
            }
            if (cell17 != null){
                excel.setFace(cell17.toString());
            }
            if (cell18 != null){
                excel.setCourtyardArea(cell18.toString());
            }
            if (cell19 != null){
                excel.setRecordPrice(cell19.toString());
            }
            if (cell20 != null){
                excel.setRecordTotalPrice(cell20.toString());
            }
            if (cell21 != null){
                excel.setOldPrice(cell21.toString());
            }
            if (cell22 != null){
                excel.setOldTotal(cell22.toString());
            }
            if (!cell23.equals("")){
                excel.setDiscountPrice(Integer.valueOf(cell23.toString()));
            }
            if (!cell24.equals("")){
                excel.setDiscountTotal(Integer.valueOf(cell24.toString()));
            }
            if (cell25.toString().length() > 0){
                excel.setNum(Integer.valueOf(cell25.toString()));
            }
            if (!cell26.equals("")){
                if (cell26.toString().equals("在售")){
                    excel.setType("0");
                }else if (cell26.toString().equals("认筹")){
                    excel.setType("1");
                }else if (cell26.toString().equals("小订")){
                    excel.setType("2");
                }else if (cell26.toString().equals("大定")){
                    excel.setType("3");
                }else if (cell26.toString().equals("成交")){
                    excel.setType("4");
                }
            }
            if (!cell27.equals("")){
                String uid = userRepository.findId(cell27.toString());
                if (uid != null){
                    excel.setRelatedAdviser(Integer.valueOf(uid));
                }
            }
            if (cell28.toString().length() > 0){
                String gid = customerRegistrationRepository.getGName(cell28.toString());
                if (gid != null){
                    excel.setRelatedParty(Integer.valueOf(gid));
                }
            }
            if (!cell29.equals("")){
                excel.setRemarks(cell29.toString());
            }
            if (!cell30.equals("")){
                excel.setProposal(cell30.toString());
            }
            /*if (cell3 != null){
                excel.setStage(cell3.toString());
            }*/
            //houseDetailRepository.save(excel);
            //默认操作
            excel.setAddTime(new Date());
            excel.setAddUid(userService.findByTelePhone(request.getSession().getAttribute("user").toString()).getId());
            excel.setAddUserName(userService.findByTelePhone(request.getSession().getAttribute("user").toString()).getName());
            excel.setSpecial("0");
            excel.setIsShow(0);
            excel.setArtificial(0);
            excel.setArtificial(0);
            list.add(excel);
        }
        houseDetailRepository.saveAll(list);//批量插入数据
        return 0;
    }

    @Override
    public List<HouseDetail> showOnSaleHouseList() {
        return houseDetailRepository.showOnSaleHouseList();
    }

    @Override
    public List getTest(List type) {
        return houseDetailRepository.getTest(type);
    }

    @Override
    public List getXk() {
        List xk = new ArrayList<>();
        List a = houseDetailRepository.getXk();
        return a;
    }

    @Override
    public int transferUser(String inputUser, String outUser) {
        return 0;
    }

    @Override
    public List<String> getFloorE(String blockCode) {
        return houseDetailRepository.getFloorE(blockCode);
    }


    public HouseDetail queryHouseDetail(HouseDetail houseDetail) {
        Integer blockCode = houseDetail.getBlockCode();
        String doorplateCode = houseDetail.getDoorplateCode();
        String unitCode = houseDetail.getUnitCode();
        if (unitCode.equals("") || unitCode == null){
            return houseDetailRepository.queryHouseDetail(blockCode,doorplateCode);
        }else{
            return houseDetailRepository.queryHouseDetailZ(blockCode,doorplateCode,unitCode);
        }
    }

    public List<String> queryBlockCode(){
        return houseDetailRepository.queryBlockCode();
    }


    public List<String> queryPropertyType(){
        return houseDetailRepository.queryPropertyType();
    }

    public List<String> queryDoorplateCode(String blockCode,String unitCode){
        if (unitCode != null){
            return houseDetailRepository.queryDoorplateCode(blockCode,unitCode);
        }else{
            return houseDetailRepository.queryDoorplateCodeZ(blockCode);
        }
    }

    public List<String> queryTung(String propertyType,String stage){
        if (stage != null){
            return houseDetailRepository.queryTung(propertyType,stage);
        }else{
            return houseDetailRepository.queryTungZ(propertyType);
        }
    }


    public List<String> queryUnitCode(String blockCode){
        return houseDetailRepository.queryUnitCode(blockCode);
    }

    public List<String> queryStage(String propertyType){
        return houseDetailRepository.queryStage(propertyType);
    }

    public int countNum(Integer relatedParty){
        return houseDetailRepository.countNum(relatedParty);
    }

    public List<String> queryDoorplateCodeZ(String blockCode){
        return houseDetailRepository.queryDoorplateCodeZ(blockCode);
    }

    public String queryZsId(Integer blockCode,String unitCode,String doorplateCode){
        if (unitCode != null){
            return houseDetailRepository.queryZsIdS(blockCode,unitCode,doorplateCode);
        }else{
            return houseDetailRepository.queryZsIdE(blockCode,doorplateCode);
        }
    }

    public HouseDetail getBlockCodeY(Integer blockCode,String unitCode,String doorplateCode){
        if (unitCode != null){
            return houseDetailRepository.getBlockCodeY(blockCode,unitCode,doorplateCode);
        }else{
            return houseDetailRepository.getBlockCodeC(blockCode,doorplateCode);
        }
    }

    public Integer clear(Integer id){
        return  houseDetailRepository.updateHouseTypeN(id);
    }

    public HouseDetail countHouse(Integer relatedParty){
        return houseDetailRepository.countHouse(relatedParty);
    }

    //判断房源是否被锁定
    public HouseDetail getLock(Integer blockCode,String unitCode,String doorplateCode){
        if (unitCode != null){
            return houseDetailRepository.getBlockCodeY(blockCode,unitCode,doorplateCode);
        }else{
            return houseDetailRepository.getBlockCodeC(blockCode,doorplateCode);
        }
    }

}
